Function Reference

RunAsSet

Initialise a set of user credentials to use during Run and RunWait operations. 2000/XP or later ONLY.

RunAsSet ( ["user", "domain", "password" [, options]] )

 

Parameters

username [optional] The user name to use.
domain [optional] The domain name to use.
password [optional] The password to use.
options [optional] 0 = do not load the user profile, 1 = (default) load the user profile, 2 = use for net credentials only

 

Return Value

Success: Returns 1--regardless of success. (If the login information was invalid, subsequent Run/RunWait commands will fail....)
Failure: Returns 0 if the operating system does not support this function.

 

Remarks

This function allows subsequent Run and RunWait functions to run as a different user (e.g. Administrator). The function only works on the 2000/XP (or later) platforms. NT4 users should install and use the SU command from the NT Resource Kit.

The "Secondary Logon service" or "RunAs service" must not be disabled if you want this function to work.

To unset the RunAs details, use the function with no parameters: RunAsSet().

 

Related

Run, RunErrorsFatal (Option), RunWait

 

Example


; This example will rerun itself with admin rights on using a local account
; Note on Vista this may not work as even though the user is admin it may
; not be elevated even after the RunAs call.  In that case use #RequireAdmin
; at the top of the script.

; Are we already admin?
If Not IsAdmin() Then
    RunAsSet('USER', @Computername, 'PASSWORD')
    Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf

MsgBox(0, 'Message', 'Now running with admin rights.')